package com.dinim.matrix.threedimensional;

import com.dinim.matrix.Matrix;

public class Matrix4x4 extends Matrix {

	public Matrix4x4() {
		super(4, 4);
	}

	public void setNextLine(double n0, double n1, double n2, double n3){
		double[] line = new double[]{n0, n1, n2, n3};
		//super.setLine(line);
	}

	public void setNextRow(double n0, double n1, double n2, double n3){
		double[] row = new double[]{n0, n1, n2, n3};
		//super.setLine(row);
	}
	
	public static Matrix4x4 generateRotationMatrixXYZ(double x, double y, double z){		
		Matrix4x4 matrixRotationXYZ = Matrix4x4.generateStandardMatrix();
		
		matrixRotationXYZ.multiplyByMatrix(Matrix4x4.generateRotationMatrixX(x));
		matrixRotationXYZ.multiplyByMatrix(Matrix4x4.generateRotationMatrixY(y));
		matrixRotationXYZ.multiplyByMatrix(Matrix4x4.generateRotationMatrixZ(z));
		
		return matrixRotationXYZ;
	}
	
	public static Matrix4x4 generateRotationMatrixX(double angle){		
		Matrix4x4 rotationMatrix = Matrix4x4.generateStandardMatrix();
		
		rotationMatrix.set(1, 1, Math.cos(Math.toRadians(angle)));
		rotationMatrix.set(1, 2, Math.sin(Math.toRadians(angle)));
		rotationMatrix.set(2, 1, Math.sin(Math.toRadians(angle)));
		rotationMatrix.set(2, 2, Math.cos(Math.toRadians(angle)));
			
		return rotationMatrix;
	}
	
	public static Matrix4x4 generateRotationMatrixY(double angle){				
		Matrix4x4 rotationMatrix = Matrix4x4.generateStandardMatrix();
		
		rotationMatrix.set(0, 0, Math.cos(Math.toRadians(angle)));
		rotationMatrix.set(2, 0, -Math.sin(Math.toRadians(angle)));
		rotationMatrix.set(0, 2, Math.sin(Math.toRadians(angle)));
		rotationMatrix.set(2, 2, Math.cos(Math.toRadians(angle)));
				
		return rotationMatrix;
	}
	
	public static Matrix4x4 generateRotationMatrixZ(double angle){	
		Matrix4x4 rotationMatrix = Matrix4x4.generateStandardMatrix();
		
		rotationMatrix.set(0, 0, Math.cos(Math.toRadians(angle)));
		rotationMatrix.set(1, 0, Math.sin(Math.toRadians(angle)));		
		rotationMatrix.set(0, 1, -Math.sin(Math.toRadians(angle)));
		rotationMatrix.set(1, 1, Math.cos(Math.toRadians(angle)));
				
		return rotationMatrix;
	}
	
	public static Matrix4x4 generateTranslationMatrixXYZ(double x, double y, double z){
		Matrix4x4 translationMatrix = (Matrix4x4)Matrix4x4.generateStandardMatrix();
		
		translationMatrix.multiplyByMatrix(Matrix4x4.generateTranslationMatrixX(x));
		translationMatrix.multiplyByMatrix(Matrix4x4.generateTranslationMatrixY(y));
		translationMatrix.multiplyByMatrix(Matrix4x4.generateTranslationMatrixZ(z));
		
		return translationMatrix;
	}
	
	public static Matrix4x4 generateTranslationMatrixX(double x){
		Matrix4x4 translationMatrix = new Matrix4x4();
		
		translationMatrix.setNextLine(1, 0, 0, x);
		translationMatrix.setNextLine(0, 1, 0, 0);
		translationMatrix.setNextLine(0, 0, 1, 0);
		translationMatrix.setNextLine(0, 0, 0, 1);
		
		return translationMatrix;
	}
	
	public static Matrix4x4 generateTranslationMatrixY(double y){
		Matrix4x4 translationMatrix = new Matrix4x4();
		
		translationMatrix.setNextLine(1, 0, 0, 0);
		translationMatrix.setNextLine(0, 1, 0, y);
		translationMatrix.setNextLine(0, 0, 1, 0);
		translationMatrix.setNextLine(0, 0, 0, 1);
		
		return translationMatrix;
	}
	
	public static Matrix4x4 generateTranslationMatrixZ(double z){		
		Matrix4x4 translationMatrix = new Matrix4x4();
				
		translationMatrix.setNextLine(1, 0, 0, 0);
		translationMatrix.setNextLine(0, 1, 0, 0);
		translationMatrix.setNextLine(0, 0, 1, z);
		translationMatrix.setNextLine(0, 0, 0, 1);
		
		return translationMatrix;
	}
	
	
	public static Matrix4x4 generateStandardMatrix(){
		Matrix4x4 standardMatrix = new Matrix4x4();
		
		standardMatrix.setNextLine(1, 0, 0, 0);
		standardMatrix.setNextLine(0, 1, 0, 0);
		standardMatrix.setNextLine(0, 0, 1, 0);
		standardMatrix.setNextLine(0, 0, 0, 1);
		
		return standardMatrix;
	}
}
